﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _TListBox {
    public partial class TListBox : Control {
        public Color BorderColor { get; set; }
        public Image ExpandImage { get; set; }
        public Image UnExpandImage { get; set; }
        public int ItemHeigth = 30;
        public Color LineColor = Color.Silver;
        public List<TListItemGroup> groupList = new List<TListItemGroup>();
        public TListItemGroup Current;

        private Pen borderPen;
        ScrollableControl itemPanel = new ScrollableControl();
        public TListBox() {
            InitializeComponent();
            itemPanel.AutoScroll = true;
            itemPanel.Location = new Point(1, 1);
            itemPanel.Size = new Size(Width - 2, Height - 2);
            itemPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left 
                | AnchorStyles.Right | AnchorStyles.Top;
            itemPanel.BackColor = BackColor;
            Controls.Add(itemPanel);
        }

        public TListItemGroup AddGroup(Image icon, string text,Color fontColor) {
            TListItemGroup group = new TListItemGroup();
            group.SuspendLayout();
            group.GroupTextColor = fontColor;
            group.tListBox = this;
            group.AddItem(icon, text);
            group.Height = ItemHeigth;
            group.Dock = DockStyle.Top;
              itemPanel.Controls.Add(group);
            //Controls.Add(group);
            group.BringToFront();
            groupList.Add(group);
            group.ResumeLayout(false);
            group.PerformLayout();
            return group;
        }

        protected override void OnPaint(PaintEventArgs pe) {
            if (borderPen == null)
                borderPen = new Pen(BorderColor,1);
            Graphics g = pe.Graphics;

            g.DrawLine(borderPen, 0, 0, Width, 0);
            g.DrawLine(borderPen, Width-1, 0, Width-1, Height);
            g.DrawLine(borderPen, 0, Height-1, Width, Height-1);
            g.DrawLine(borderPen, 0, 0, 0, Height);
        }
    }
}
